import vue from '@vitejs/plugin-vue'
import path from 'node:path'
import { defineConfig } from 'vite'
import WindiCSS from 'vite-plugin-windicss'
import { proxyReqListener } from './tools/proxyReqListener'
import { visualizer } from 'rollup-plugin-visualizer'
import viteCompression from 'vite-plugin-compression'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        WindiCSS(),
        visualizer({
            // gzipSize: true,
            // brotliSize: true,
            emitFile: true,
            // filename: 'visualizer.html', //分析图生成的文件名
            open: true, //如果存在本地服务端口，将在打包后自动展示
        }),
        viteCompression()
    ],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src'),
        },
    },
    base: './',
    server: {
        hmr: true,
        proxy: {
            '/api': {
                target: 'http://localhost:3000',
                rewrite: (path) => path.replace(/^\/api/, ''),
            },
            '/localhost-devServer': {
                target: '/',
                configure: (proxy, _options) => {
                    console.log(111)
                    proxy.on('proxyReq', proxyReqListener)
                },
            },
        },
    },
})
